var objFs = {

	newFolder: function(){

	},

	uploadFile: function(params){
		var objFormData = new FormData($('#upload-dialog form')[0]);

		console.log(params);

		for(var key in params.data) {
			console.log(key + " " + params.data[key]);
			objFormData.append(key, params.data[key]);
		}

		$.ajax({
			url: '/api/file/save',  //server script to process data
			type: 'POST',
			xhr: function() {  // custom xhr
				myXhr = $.ajaxSettings.xhr();
				if(myXhr.upload){ // check if upload property exists
					myXhr.upload.addEventListener('progress', function(e){
						if(e.lengthComputable){
							//get the progress
							var loadedPercent = parseInt((e.loaded/(e.total/100)));

							//progress bar max width
							var intMaxWidth = jQuery('#upload-dialog .progress-bar').width();
							var intPercentWidth = (intMaxWidth/100);

							//update the progress bar
							jQuery('#upload-dialog .progress-bar .progress').css("width", (intPercentWidth * loadedPercent) + "px");
						}
					}, false); // for handling the progress of the upload
				}
				return myXhr;
			},
			//Ajax events
			success: function(data) {
				params.success(data);
			},
			error: function(data) {
				params.error(data);
			},
			// Form data
			data: objFormData,
			//Options to tell JQuery not to process data or worry about content-type
			cache: false,
			contentType: false,
			processData: false
		});
	},

	loadList: function(params){
		objApi.get({
			url: "/files?path=" + params.path,
			success: function(data){
				//get the dir contents
				var aryContents = data.data.contents;
				var strHtml = "";

				//create the dir list
				for(var i in aryContents){
					var html  = '<div class="item" id="item_'+aryContents[i]._id+'">';
							html += '<div class="icon">';
								if(aryContents[i].is_dir == 1) {
									html += '<span class="ui-icon ui-icon-folder"></span>';
								} else {
									html += '<span class="ui-icon ui-icon-file"></span>';
								}
							html += '</div>';
							html += '<div class="name">';
								if(aryContents[i].is_dir == 1) {
									html += '<a href="/main' + strPath +  aryContents[i].name +'/">' + aryContents[i].name+ '</a>';
								} else {
									html += aryContents[i].name;
								}
							html += '</div>';
							html += '<div class="type">';
								if(aryContents[i].is_dir == 1) {
									html += "Folder";
								} else {
									html += aryContents[i].mime;
								}
							html += '</div>';
							html += '<div class="last-change">';
								html += aryContents[i].last_change;
							html += '</div>';
						html += '</div>';

					strHtml += html;
				}

				params.callback(data.data._id, strHtml);
			},
			error: function(){
				params.callback("");
			}
		});
	}
};